package com.xdf.wxbebarrel.model;


public class WxJsApiTicket {
    private Integer errcode;
    private String errmsg;
    private String ticket;
    private Long expires_in;
    private Long maxTimeStamp;// 创建对象时初始化过期时间戳（毫秒）

    private static final long serialVersionUID = 1L;

    public WxJsApiTicket(){

    }

    // expires_in:微信默认有效期7200秒
    public WxJsApiTicket(Integer errcode, String errmsg, String ticket, Long expires_in){
        this.errcode = errcode;
        this.errmsg = errmsg;
        this.ticket = ticket;
        this.expires_in = expires_in;
        maxTimeStamp = System.currentTimeMillis() + expires_in * 1000;// 转换为毫秒单位
    }

    // 返回 true 表示过期了
    public boolean isExpired(){
        return System.currentTimeMillis()>maxTimeStamp;
    }

    public Integer getErrcode() {
        return errcode;
    }

    public void setErrcode(Integer errcode) {
        this.errcode = errcode;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public String getTicket() {
        return ticket;
    }

    public void setTicket(String ticket) {
        this.ticket = ticket;
    }

    public Long getExpires_in() {
        return expires_in;
    }

    public void setExpires_in(Long expires_in) {
        this.expires_in = expires_in;
    }

    public Long getMaxTimeStamp() {
        return maxTimeStamp;
    }

    public void setMaxTimeStamp(Long maxTimeStamp) {
        this.maxTimeStamp = maxTimeStamp;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    @Override
    public String toString() {
        return "WxJsApiTicket{" +
                "errcode=" + errcode +
                ", errmsg='" + errmsg + '\'' +
                ", ticket='" + ticket + '\'' +
                ", expires_in=" + expires_in +
                ", maxTimeStamp=" + maxTimeStamp +
                '}';
    }
}
